/* $Header: sig_type.c,v 2.2 01/10/02 10:33:06 przybyls Exp $ */

/***********************************************************************/
/*                                                                     */
/*                  Copyright Hewlett-Packard Co. 1992                 */
/*                                                                     */
/***********************************************************************/

/***********************************************************************/
/* MODULE NAME:  sig_type.c                                            */
/* ============                                                        */
/*                                                                     */
/* Author:  Lesley Freed                                               */
/*                                                                     */
/* MODULE PURPOSE:  To provide the Set, Get, and Check functions for   */
/*                  the user interface to the signal type selection.   */
/*                                                                     */
/***********************************************************************/


/*****************************/
/*   GLOBAL INCLUDE FILES    */
/*****************************/

#include <typedefs.h>
#include <p_wkfile.h>
#include <wkfile.h>
#include <ramps.h>
#include <zone_config.h>
#include <config.h>
#include <i_op.h>
#include <p_status.h>
#include <zone_status.h>
#include <status.h>
#include <error.h>
#include <sig_types.h>
#include <sig_ui.h>
#include <zone_ui.h>
#include <dig_path.h>
#include <sigpath.h>
#include <det_ui.h>

#include <exception.h>
#include <glp.h>

#include <p_ui.h>
#include <math.h>

#include <diag.h>

/*****************************/
/*   LOCAL INCLUDE FILES     */
/*****************************/


/*****************************/
/*   GLOBAL VARIABLES        */
/*****************************/

   PLOT_CONSTANTS Signal1_Consts;
   PLOT_CONSTANTS Signal2_Consts;

/*****************************/
/*   LOCAL DEFINES           */
/*****************************/

#define PRES_SCALE 0  /* Flag to use look up scale factor */

/*****************************/
/*   STATIC VARIABLES        */
/*****************************/



/*****************************/
/*   IMPLEMENT SECTION       */
/*****************************/

const PLOT_CONSTANTS TEMP_SIG_CONSTS = { TEMP_SIG_OFFSET, SIG_SCALE_FACTOR, 256*64 };

const PLOT_CONSTANTS NO_CHANGE_CONSTS = { 0, SIG_SCALE_FACTOR, 1 };

const PLOT_CONSTANTS HUNDRED_MICRO_VOLT_CONSTS = { 0, 10000*SIG_SCALE_FACTOR, 10*65536 };

/* DAC output (in V):  90.9 mV/V gain */
const PLOT_CONSTANTS DAC_OUT_CONSTS = { 0, 11001*SIG_SCALE_FACTOR, 65536*10 };

/* Attn output (in mV):  318 mV/V gain and attn of 2000 */
const PLOT_CONSTANTS ATTN_OUT_CONSTS = { 0, 31447*SIG_SCALE_FACTOR, 65536*20 };

const PLOT_CONSTANTS MON_5V_CONSTS = { 0,  11012*SIG_SCALE_FACTOR, 65536*10 };

const PLOT_CONSTANTS MON_15VPOS_CONSTS = { 0, 39341*SIG_SCALE_FACTOR, 65536*10 };

const PLOT_CONSTANTS MON_15VNEG_CONSTS = { 73274, 42465*SIG_SCALE_FACTOR, 65536*10 };

const PLOT_CONSTANTS MODULE_TEMP_CONSTS = { 0, SIG_SCALE_FACTOR, 64 };

const PLOT_CONSTANTS PNEU_VOLT_CONSTS = { 0, 1000*SIG_SCALE_FACTOR, 13107 };

const PLOT_CONSTANTS MON_10_VOLT_CONSTS = { 0, 45*500*SIG_SCALE_FACTOR, 2*65536 };

/*********************/
/* Scale Factor Data */
/*********************/

/* Labels: */

   /* Detector units: */
const char FID_LABEL[]       = "pA";
const char TCD_LABEL[]       = "25 uV";
const char ECD_LABEL[]       = "5 Hz";
const char uECD_LABEL[]      = "Hz";
const char NPD_LABEL[]       = "pA";
const char FPD_LABEL[]       = "150 pA";
const char AIB_LABEL[]       = "15 uV";
const char LDID_LABEL[]      = "pA";         /* REVISIT */
const char UNKNOWN_LABEL[]   = "unknown";

const char TEMP_LABEL[]      = "degrees C";
const char PSI_LABEL[]       = "psi";
const char KPA_LABEL[]       = "kPa";
const char BAR_LABEL[]       = "bar";
const char FLOW_LABEL[]      = "mL/min";

const char VOLTS_LABEL[]     = "Volts";

const char COUNTS_LABEL[]    = "counts";

/* Conversion constants: */

   /* For the detector and column compensation signals use the label pointer  */
   /* position to flag that the units are configuration or stored profile     */
   /* dependent.                                                              */

const SCALE_CONSTANTS F_DET_SCALE     = { 1, 240*32, SIGNAL_DET, (char const *)0 };
const SCALE_CONSTANTS B_DET_SCALE     = { 1, 240*32, SIGNAL_DET, (char const *)1 };
const SCALE_CONSTANTS CCOMP1_SCALE    = { 1, 240*32, SIGNAL_DET, (char const *)2 };
const SCALE_CONSTANTS CCOMP2_SCALE    = { 1, 240*32, SIGNAL_DET, (char const *)3 };

const SCALE_CONSTANTS TEST_PLOT_SCALE = { 1, 240*32, SIGNAL_DET, &COUNTS_LABEL[0] };

const SCALE_CONSTANTS TEMP_SCALE      = { 1, 240*32, SIGNAL_DET, &TEMP_LABEL[0] };
const SCALE_CONSTANTS PSI_SCALE       = { 1, 2400*32, SIGNAL_D2, &PSI_LABEL[0] };
const SCALE_CONSTANTS KPA_SCALE       = { 1, 240*32, SIGNAL_DET, &KPA_LABEL[0] };
const SCALE_CONSTANTS BAR_SCALE       = { 1, 24000*32, SIGNAL_D3, &BAR_LABEL[0] };
const SCALE_CONSTANTS FLOW_SCALE      = { 1, 240*32, SIGNAL_DET, &FLOW_LABEL[0] };
const SCALE_CONSTANTS MV_SCALE        = { 1, 24000*32, SIGNAL_D3, &VOLTS_LABEL[0] };
const SCALE_CONSTANTS HV_SCALE        = { 1, 240000*32, SIGNAL_D4, &VOLTS_LABEL[0] };
const SCALE_CONSTANTS COUNTS_SCALE    = { 1, 1*32, SIGNAL_UNSCALED, &COUNTS_LABEL[0] };


/***********************************************************************/
/* TABLE:  ALT_SIG_TYPE_TABLE                                          */
/* ======                                                              */
/*                                                                     */
/* PURPOSE:  To define the look-up table for the alternate signal      */
/*           types.                                                    */
/*                                                                     */
/* LIMITATIONS: The table must be in the same order as the SIG_TYPE    */
/*              enumerated type for signals >= OVEN_TEMP_SIGNAL.       */
/*                                                                     */
/***********************************************************************/


const PLOT_INFO ALT_SIG_TYPE_TABLE[] =
{
/* OVEN_TEMP_SIGNAL: */  { &Oven_Table.zone_temp, &TEMP_SIG_CONSTS, SIZE_32_BIT, &TEMP_SCALE },
/* DETA_TEMP_SIGNAL: */  { &Deta_Table.zone_temp, &TEMP_SIG_CONSTS, SIZE_32_BIT, &TEMP_SCALE },
/* DETB_TEMP_SIGNAL: */  { &Detb_Table.zone_temp, &TEMP_SIG_CONSTS, SIZE_32_BIT, &TEMP_SCALE },
/* INJA_TEMP_SIGNAL: */  { &Inja_Table.zone_temp, &TEMP_SIG_CONSTS, SIZE_32_BIT, &TEMP_SCALE },
/* INJB_TEMP_SIGNAL: */  { &Injb_Table.zone_temp, &TEMP_SIG_CONSTS, SIZE_32_BIT, &TEMP_SCALE },
/* AUXA_TEMP_SIGNAL: */  { &Auxa_Table.zone_temp, &TEMP_SIG_CONSTS, SIZE_32_BIT, &TEMP_SCALE },
/* AUXB_TEMP_SIGNAL: */  { &Auxb_Table.zone_temp, &TEMP_SIG_CONSTS, SIZE_32_BIT, &TEMP_SCALE },

/* COL1_FLOW_SIGNAL: */  { C1_FLOW_ACTUAL_SIGNAL_SOURCE, 0, SIZE_32_BIT, &FLOW_SCALE },
/* COL2_FLOW_SIGNAL: */  { C2_FLOW_ACTUAL_SIGNAL_SOURCE, 0, SIZE_32_BIT, &FLOW_SCALE },

/* COL1_PRES_SIGNAL: */  { (U_INT32 *)C1_PRES_ACTUAL_SIGNAL_SOURCE, 0,SIZE_16_BIT, PRES_SCALE },
/* COL2_PRES_SIGNAL: */  { (U_INT32 *)C2_PRES_ACTUAL_SIGNAL_SOURCE, 0,SIZE_16_BIT, PRES_SCALE },

/* F_INLET_FLOW: */  { FI_FLOW_ACTUAL_SIGNAL_SOURCE, 0, SIZE_32_BIT, &FLOW_SCALE },
/* B_INLET_FLOW: */  { BI_FLOW_ACTUAL_SIGNAL_SOURCE, 0, SIZE_32_BIT, &FLOW_SCALE },
/* F_INLET_PRES: */  { (U_INT32 *)FI_PRES_ACTUAL_SIGNAL_SOURCE, 0, SIZE_16_BIT, PRES_SCALE },
/* B_INLET_PRES: */  { (U_INT32 *)BI_PRES_ACTUAL_SIGNAL_SOURCE, 0, SIZE_16_BIT, PRES_SCALE },

/* F_DET_GAS1_PRES: */ { (U_INT32 *)FD_F_PRES_ACTUAL_SIGNAL_SOURCE,0, SIZE_16_BIT, PRES_SCALE },
/* F_DET_GAS2_PRES: */ { (U_INT32 *)FD_U_PRES_ACTUAL_SIGNAL_SOURCE,0, SIZE_16_BIT, PRES_SCALE },
/* F_DET_GAS3_PRES: */ { (U_INT32 *)FD_M_PRES_ACTUAL_SIGNAL_SOURCE,0, SIZE_16_BIT, PRES_SCALE },
/* B_DET_GAS1_PRES: */ { (U_INT32 *)BD_F_PRES_ACTUAL_SIGNAL_SOURCE,0, SIZE_16_BIT, PRES_SCALE },
/* B_DET_GAS2_PRES: */ { (U_INT32 *)BD_U_PRES_ACTUAL_SIGNAL_SOURCE,0, SIZE_16_BIT, PRES_SCALE },
/* B_DET_GAS3_PRES: */ { (U_INT32 *)BD_M_PRES_ACTUAL_SIGNAL_SOURCE,0, SIZE_16_BIT, PRES_SCALE },
/* F_DET_GAS1_FLOW: */ { FD_F_FLOW_ACTUAL_SIGNAL_SOURCE, 0, SIZE_32_BIT, &FLOW_SCALE },
/* F_DET_GAS2_FLOW: */ { FD_U_FLOW_ACTUAL_SIGNAL_SOURCE, 0, SIZE_32_BIT, &FLOW_SCALE },
/* F_DET_GAS3_FLOW: */ { FD_M_FLOW_ACTUAL_SIGNAL_SOURCE, 0, SIZE_32_BIT, &FLOW_SCALE },
/* B_DET_GAS1_FLOW: */ { BD_F_FLOW_ACTUAL_SIGNAL_SOURCE, 0, SIZE_32_BIT, &FLOW_SCALE },
/* B_DET_GAS2_FLOW: */ { BD_U_FLOW_ACTUAL_SIGNAL_SOURCE, 0, SIZE_32_BIT, &FLOW_SCALE },
/* B_DET_GAS3_FLOW: */ { BD_M_FLOW_ACTUAL_SIGNAL_SOURCE, 0, SIZE_32_BIT, &FLOW_SCALE },

/* AUX_3_PRES       */ { (U_INT32 *)A3_PRES_ACTUAL_SIGNAL_SOURCE, 0, SIZE_16_BIT, PRES_SCALE },
/* AUX_4_PRES       */ { (U_INT32 *)A4_PRES_ACTUAL_SIGNAL_SOURCE, 0, SIZE_16_BIT, PRES_SCALE },
/* AUX_5_PRES       */ { (U_INT32 *)A5_PRES_ACTUAL_SIGNAL_SOURCE, 0, SIZE_16_BIT, PRES_SCALE },

/****************************/
/* Diagnostic type signals: */
/****************************/

/* MUX_ADC_OFFSET:   */  { (U_INT32 *)&Mux_Adc_Offset.offset,
                           &HUNDRED_MICRO_VOLT_CONSTS, SIZE_16_BIT_SIGNED,
                           &HV_SCALE },

/* OVEN_RTD_RDG:     */  { (U_INT32 *)&Oven_Table.zone_rdg,
                            &HUNDRED_MICRO_VOLT_CONSTS, SIZE_16_BIT, &HV_SCALE },

/* F_DET_RTD_RDG:    */  { (U_INT32 *)&Deta_Table.zone_rdg,
                            &HUNDRED_MICRO_VOLT_CONSTS, SIZE_16_BIT, &HV_SCALE },

/* B_DET_RTD_RDG:    */  { (U_INT32 *)&Detb_Table.zone_rdg,
                            &HUNDRED_MICRO_VOLT_CONSTS, SIZE_16_BIT, &HV_SCALE },

/* F_INLET_RTD_RDG:  */  { (U_INT32 *)&Inja_Table.zone_rdg,
                            &HUNDRED_MICRO_VOLT_CONSTS, SIZE_16_BIT, &HV_SCALE },

/* B_INLET_RTD_RDG:  */  { (U_INT32 *)&Injb_Table.zone_rdg,
                            &HUNDRED_MICRO_VOLT_CONSTS, SIZE_16_BIT, &HV_SCALE },

/* AUX_1_RTD_RDG:    */  { (U_INT32 *)&Auxa_Table.zone_rdg,
                            &HUNDRED_MICRO_VOLT_CONSTS, SIZE_16_BIT, &HV_SCALE },

/* AUX_2_RTD_RDG:    */  { (U_INT32 *)&Auxb_Table.zone_rdg,
                            &HUNDRED_MICRO_VOLT_CONSTS, SIZE_16_BIT, &HV_SCALE },

/* ATTN1_SIGNAL:     */  { (U_INT32 *)&Attn1_Rdg,
                            &ATTN_OUT_CONSTS, SIZE_16_BIT, &HV_SCALE },

/* ATTN2_SIGNAL:     */  { (U_INT32 *)&Attn2_Rdg,
                            &ATTN_OUT_CONSTS, SIZE_16_BIT, &HV_SCALE },

/* DAC1_SIGNAL:      */  { (U_INT32 *)&DAC1_Rdg,
                            &DAC_OUT_CONSTS, SIZE_16_BIT, &HV_SCALE },

/* DAC2_SIGNAL:      */  { (U_INT32 *)&DAC2_Rdg,
                            &DAC_OUT_CONSTS, SIZE_16_BIT, &HV_SCALE },

/* MON_5V_SIGNAL:    */  { (U_INT32 *)&Mon_5V_Rdg,
                           &MON_5V_CONSTS, SIZE_16_BIT, &MV_SCALE },

/* MON_24V_SIGNAL:   */  { (U_INT32 *)&Mon_24V_Rdg,
                           &MON_15VPOS_CONSTS, SIZE_16_BIT, &MV_SCALE },

/* MON_15VPOS_SIGNAL:*/  { (U_INT32 *)&Mon_15Vpos_Rdg,
                           &MON_15VPOS_CONSTS, SIZE_16_BIT, &MV_SCALE },

/* MON_15VNEG_SIGNAL:*/  { (U_INT32 *)&Mon_15Vneg_Rdg,
                           0, SIZE_16_BIT, &MV_SCALE },

/* DET_DIAGA_SIGNAL: */  { (U_INT32 *)&Det_Diaga_Rdg,
                            &HUNDRED_MICRO_VOLT_CONSTS, SIZE_16_BIT, &HV_SCALE},

/* DET_DIAGB_SIGNAL: */  { (U_INT32 *)&Det_Diagb_Rdg,
                            &HUNDRED_MICRO_VOLT_CONSTS, SIZE_16_BIT, &HV_SCALE},

/* DET_DIAGC_SIGNAL: */  { (U_INT32 *)&Det_Diagc_Rdg,
                            &HUNDRED_MICRO_VOLT_CONSTS, SIZE_16_BIT, &HV_SCALE},

/* DET_DIAGD_SIGNAL: */  { (U_INT32 *)&Det_Diagd_Rdg,
                            &HUNDRED_MICRO_VOLT_CONSTS, SIZE_16_BIT, &HV_SCALE},

/* ATM_PRES_SIGNAL:        */ { (U_INT32 *)ATMOSPHERIC_PRES_SIGNAL_SOURCE,
                                0, SIZE_16_BIT, PRES_SCALE},

/* F_INL_MOD_TEMP_SIGNAL:  */ { (U_INT32 *)FI_MODULE_TEMP_SIGNAL_SOURCE,
                                &MODULE_TEMP_CONSTS, SIZE_16_BIT, &TEMP_SCALE},

/* B_INL_MOD_TEMP_SIGNAL:  */ { (U_INT32 *)BI_MODULE_TEMP_SIGNAL_SOURCE,
                                &MODULE_TEMP_CONSTS, SIZE_16_BIT, &TEMP_SCALE},

/* F_DET_MOD_TEMP_SIGNAL:  */ { (U_INT32 *)FD_MODULE_TEMP_SIGNAL_SOURCE,
                                &MODULE_TEMP_CONSTS, SIZE_16_BIT, &TEMP_SCALE},

/* B_DET_MOD_TEMP_SIGNAL:  */ { (U_INT32 *)BD_MODULE_TEMP_SIGNAL_SOURCE,
                                &MODULE_TEMP_CONSTS, SIZE_16_BIT, &TEMP_SCALE},

/* AUX_MOD_TEMP_SIGNAL:    */ { (U_INT32 *)PA_MODULE_TEMP_SIGNAL_SOURCE,
                                &MODULE_TEMP_CONSTS, SIZE_16_BIT, &TEMP_SCALE},

/* PNEU_10V_SIGNAL:        */ { (U_INT32 *)PNEU_10_VOLT_SIGNAL_SOURCE,
                                &MON_10_VOLT_CONSTS, SIZE_16_BIT, &HV_SCALE},

/* PNEU_ADC_OFFSET_SIGNAL: */ { (U_INT32 *)PNEU_ADC_OFFSET_SIGNAL_SOURCE,
                                &PNEU_VOLT_CONSTS, SIZE_16_BIT, &HV_SCALE},

/* F_INL_GAS_VOLTS_SIGNAL: */ { (U_INT32 *)FI_FS_GAS_DRIVE_SIGNAL_SOURCE,
                                &PNEU_VOLT_CONSTS, SIZE_16_BIT, &HV_SCALE},

/* B_INL_GAS_VOLTS_SIGNAL: */ { (U_INT32 *)BI_FS_GAS_DRIVE_SIGNAL_SOURCE,
                                &PNEU_VOLT_CONSTS, SIZE_16_BIT, &HV_SCALE},

/* For diagnostic use: */

/* F_INLET_FLOW_SETPT: */  { FI_FLOW_SETPT_SIGNAL_SOURCE, 0, SIZE_32_BIT, &FLOW_SCALE },
/* B_INLET_FLOW_SETPT: */  { BI_FLOW_SETPT_SIGNAL_SOURCE, 0, SIZE_32_BIT, &FLOW_SCALE },
/* F_INL_PRES_SETPT */ { (U_INT32 *)FI_PRES_SETPT_SIGNAL_SOURCE, 0, SIZE_16_BIT, PRES_SCALE },
/* B_INL_PRES_SETPT */ { (U_INT32 *)BI_PRES_SETPT_SIGNAL_SOURCE, 0, SIZE_16_BIT, PRES_SCALE },
/* F_DET_GAS1_PRES_SETPT: */
                      { (U_INT32 *)FD_F_PRES_SETPT_SIGNAL_SOURCE, 0, SIZE_16_BIT, PRES_SCALE },
/* F_DET_GAS2_PRES_SETPT: */
                      { (U_INT32 *)FD_U_PRES_SETPT_SIGNAL_SOURCE, 0, SIZE_16_BIT, PRES_SCALE },
/* F_DET_GAS3_PRES_SETPT: */
                      { (U_INT32 *)FD_M_PRES_SETPT_SIGNAL_SOURCE, 0, SIZE_16_BIT, PRES_SCALE },
/* B_DET_GAS1_PRES_SETPT: */
                      { (U_INT32 *)BD_F_PRES_SETPT_SIGNAL_SOURCE, 0, SIZE_16_BIT, PRES_SCALE },
/* B_DET_GAS2_PRES_SETPT: */
                      { (U_INT32 *)BD_U_PRES_SETPT_SIGNAL_SOURCE, 0, SIZE_16_BIT, PRES_SCALE },
/* B_DET_GAS3_PRES_SETPT: */
                      { (U_INT32 *)BD_M_PRES_SETPT_SIGNAL_SOURCE, 0, SIZE_16_BIT, PRES_SCALE },
/* F_DET_GAS1_FLOW_SETPT: */ { FD_F_FLOW_SETPT_SIGNAL_SOURCE, 0, SIZE_32_BIT, &FLOW_SCALE },
/* F_DET_GAS2_FLOW_SETPT: */ { FD_U_FLOW_SETPT_SIGNAL_SOURCE, 0, SIZE_32_BIT, &FLOW_SCALE },
/* F_DET_GAS3_FLOW_SETPT: */ { FD_M_FLOW_SETPT_SIGNAL_SOURCE, 0, SIZE_32_BIT, &FLOW_SCALE },
/* B_DET_GAS1_FLOW_SETPT: */ { BD_F_FLOW_SETPT_SIGNAL_SOURCE, 0, SIZE_32_BIT, &FLOW_SCALE },
/* B_DET_GAS2_FLOW_SETPT: */ { BD_U_FLOW_SETPT_SIGNAL_SOURCE, 0, SIZE_32_BIT, &FLOW_SCALE },
/* B_DET_GAS3_FLOW_SETPT: */ { BD_M_FLOW_SETPT_SIGNAL_SOURCE, 0, SIZE_32_BIT, &FLOW_SCALE },
/* AUX_3_PRES_SETPT */ { (U_INT32 *)A3_PRES_SETPT_SIGNAL_SOURCE, 0, SIZE_16_BIT, PRES_SCALE },
/* AUX_4_PRES_SETPT */ { (U_INT32 *)A4_PRES_SETPT_SIGNAL_SOURCE, 0, SIZE_16_BIT, PRES_SCALE },
/* AUX_5_PRES_SETPT */ { (U_INT32 *)A5_PRES_SETPT_SIGNAL_SOURCE, 0, SIZE_16_BIT, PRES_SCALE }
};



/* Define the look up table for the unscaled signals */

const UNSCALED_PLOT_INFO UNSCALED_SIG_TYPE_TABLE[] =
{
/* RAW_ADC_RDG:      */  { (U_INT32 *)&Reading, SIZE_16_BIT },

/* RAW_RDG_NOISE:    */  { (U_INT32 *)&Reading_Noise, SIZE_16_BIT },

/* ADC_NOISE_SIGNAL: */  { (U_INT32 *)&Mux_Adc_Offset.noise,
                           SIZE_16_BIT_SIGNED },

/* LINE_SENSE_SIGNAL:*/  { (U_INT32 *)&Zone_Status.line_voltage_percent, SIZE_8_BIT },

/* DETA_1ST_ORDER_SIG:*/ { (U_INT32 *)&Dsp_In.deta_1st, SIZE_8_BIT },
/* DETB_1ST_ORDER_SIG:*/ { (U_INT32 *)&Dsp_In.detb_1st, SIZE_8_BIT },
/* DETA_2ND_ORDER_SIG:*/ { (U_INT32 *)&Dsp_In.deta_2nd, SIZE_8_BIT },
/* DETB_2ND_ORDER_SIG:*/ { (U_INT32 *)&Dsp_In.detb_2nd, SIZE_8_BIT },

/* DETA_DATA_SIG:    */  { (U_INT32 *)&Dsp_In.deta_data, SIZE_32_BIT },
/* DETB_DATA_SIG:    */  { (U_INT32 *)&Dsp_In.detb_data, SIZE_32_BIT },
/* DETA_OFFSET_SIG:  */  { (U_INT32 *)&DetectorA.offset, SIZE_32_BIT },
/* DETB_OFFSET_SIG:  */  { (U_INT32 *)&DetectorB.offset, SIZE_32_BIT },

};


/* Returns the index into the table for alternate signals */
INT16 GetAlternateSignalIndex( SIG_TYPE type )
{
   return( (INT16)type - (INT16)FIRST_ALTERNATE_SIGNAL );
}

/* Returns the index into the table for unscaled signals */
INT16 GetUnscaledSignalIndex( SIG_TYPE type )
{
   return( (INT16)type - (INT16)FIRST_UNSCALED_SIGNAL );
}


/***********************************************************************/
/* FUNCTION:  GetCalculatedPlotConstants                               */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:  To return whether or not a signal requires calculated     */
/*           plot constants.                                           */
/*                                                                     */
/* RETURNED VALUE:  TRUE = requires calculated constants               */
/*                  FALSE = use constants in table                     */
/*                                                                     */
/* GLOBALS USED:  none                                                 */
/*                                                                     */
/* CALLS:                                                              */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/***********************************************************************/

BIT8 CalculatedConstants( SIG_TYPE type )
{
   if ( UnscaledSignal( type ) )
   {
      return( FALSE );
   }

   /* See if the pointer to the plot constants is 0, indicating the
      constants change and need to be calculated */
   if ( ALT_SIG_TYPE_TABLE[GetAlternateSignalIndex( type )].pconstants == 0 )
   {
      return( TRUE );
   }

   return( FALSE );

}

pPLOT_CONSTANTS GetCalculatedPlotConstants( pSIG_TABLE psignal, SIG_TYPE type )
{
   pPLOT_CONSTANTS pcalc_constants;

   if ( psignal->chan == SIGNAL1 )
   {
      pcalc_constants = &Signal1_Consts;
   }
   else
   {
      pcalc_constants = &Signal2_Consts;
   }

   /* Get the plot values to use */
   SetPlotConstants( type, pcalc_constants );

   return ( pcalc_constants );
}

/***********************************************************************/
/* FUNCTION:  GetAlternateSignalScale                                  */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:  To get the scale factor information for an alterate       */
/*           signal.                                                   */
/*                                                                     */
/* RETURNED VALUE:  pSCALE_CONSTANTS                                   */
/*                                                                     */
/* GLOBALS USED:  ALT_SIG_TYPE_TABLE                                   */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/***********************************************************************/

static SCALE_CONSTANTS const *GetAlternateSignalScale( U_INT16 index )
{
   SCALE_CONSTANTS const *pscale;

   pscale = ALT_SIG_TYPE_TABLE[index].pscale;

   /* See if its a pressure signal, they have changing units */
   if ( pscale == PRES_SCALE )
   {
      switch ( GetPresUnits() )
      {
         default:
         case DISPLAY_PSI:  pscale = &PSI_SCALE;
                            break;
         case DISPLAY_KPA:  pscale = &KPA_SCALE;
                            break;
         case DISPLAY_BAR:  pscale = &BAR_SCALE;
                            break;
      }
   }
   return pscale;
}

/***********************************************************************/
/* FUNCTION:  SetAlternateSignalType                                   */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:  To set the signal type to an alternal type signal         */
/*                                                                     */
/* RETURNED VALUE: none                                                */
/*                                                                     */
/* GLOBALS USED:  Active Wkfile, Signal1 or 2                          */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/***********************************************************************/

static void SetAlternateSignalType( pSIG_TABLE psignal, SIG_TYPE type,
                                    BIT8 set_wkfile_flag )
{

   BIT8            unscaled_flag;
   BIT8            calc_flag;
   INT16           index;
   U_INT32         *addr;
   DATA_SIZE       size;
   SCALE_CONSTANTS const *pscale;

   calc_flag   = CalculatedConstants( type );
   unscaled_flag = UnscaledSignal( type );

   /* First, see how we should scale the signal.  There are three            */
   /* alternatives: 1) no scaling, 2) use look up table constants,           */
   /* and 3) use constants from SetPlotConstants                             */

   if ( unscaled_flag )
   {
      index  = GetUnscaledSignalIndex( type );
      addr   = UNSCALED_SIG_TYPE_TABLE[index].addr;
      size   = UNSCALED_SIG_TYPE_TABLE[index].size;
   }
   else
   {
      index  = GetAlternateSignalIndex( type );
      addr  = ALT_SIG_TYPE_TABLE[index].addr;
      size  = ALT_SIG_TYPE_TABLE[index].size;
   }

   pscale = GetSignalScaleFactor( type );

   /* Set the signal to point to a specific memory location and set the */
   /* type.  Also disable column compensation.                          */

   INTERRUPTS_OFF
      if ( set_wkfile_flag == TRUE )
      {
         psignal->active_wkfile->size     = (BIT8)size;
         psignal->active_wkfile->signal   = (BIT8)type;
         psignal->active_wkfile->plot     = addr;
      }

      psignal->plot_size            = size;
      psignal->signal               = type;
      psignal->plot                 = addr;
      psignal->pscale               = pscale;

      /* Disable column compensation mode */
      psignal->ccomp_mode           = DISABLE_CCOMP;

      if ( ! unscaled_flag )
      {
         if ( calc_flag )
         {
            psignal->pconstants = GetCalculatedPlotConstants( psignal, type );
         }
         else
         {
            psignal->pconstants = ALT_SIG_TYPE_TABLE[index].pconstants;
         }
      }

      /* We do not need to convert signal */
      psignal->sig_conv_mode = NULL_CONV;

   INTERRUPTS_ON
}



/***********************************************************************/
/* FUNCTION:                                                           */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:                                                            */
/*                                                                     */
/* RETURNED VALUE:                                                     */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/* CALLS:                                                              */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/***********************************************************************/

void SetDspSignalType( pSIG_TABLE signal, SIG_TYPE type )
{
   SIG_TYPE dsp_type;

   /* Default to force the signal from the dsp to zero output. */
   dsp_type = (SIG_TYPE)ZERO_SIGNAL;

   switch( type )
   {
      case DETA_SIGNAL:
      case F_CCOMP1_SIGNAL:
      case F_CCOMP2_SIGNAL:
         /* Check to see if the front detector is turned off, if so then  */
         /* force the signal from the dsp to zero.                        */
         if ( GetDetOnOff( FRONT ) )
         {
            dsp_type = DETA_SIGNAL;
         }
         break;

      case DETA_B_SIGNAL:
      case DETB_A_SIGNAL:
         /* Check to see if either the front or the back detector is      */
         /* turned off, if so then force the signal from the dsp to zero. */
         if (( GetDetOnOff(FRONT) ) || ( GetDetOnOff(BACK) ))
         {
            dsp_type = type;
         }
         break;

      case DETB_SIGNAL:
      case B_CCOMP1_SIGNAL:
      case B_CCOMP2_SIGNAL:
         /* Check to see if the back detector is turned off, if so then   */
         /* force the signal from the dsp to zero.                        */
         if ( GetDetOnOff( BACK ) )
         {
            dsp_type = DETB_SIGNAL;
         }
         break;
    }

    if ( signal == pSIGNAL1 )
    {
       Dsp_Out.sig1_def = (U_INT16)dsp_type;
    }
    else if ( signal == pSIGNAL2 )
    {
       Dsp_Out.sig2_def = (U_INT16)dsp_type;
    }
}


/***********************************************************************/
/* FUNCTION:                                                           */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:                                                            */
/*                                                                     */
/* RETURNED VALUE:                                                     */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/* CALLS:                                                              */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/***********************************************************************/

static SCALE_CONSTANTS const *GetDetScaleFactor( SIG_TYPE type )
{
   SCALE_CONSTANTS const *pscale;

   switch( type )
   {
      case COL_COMP1_SIGNAL:
         pscale = &CCOMP1_SCALE;
         break;

      case COL_COMP2_SIGNAL:
         pscale = &CCOMP2_SCALE;
         break;

      case DETA_SIGNAL:
      case F_CCOMP1_SIGNAL:
      case F_CCOMP2_SIGNAL:
      case DETA_B_SIGNAL:
      case DETB_A_SIGNAL:
         pscale = &F_DET_SCALE;
         break;

      case DETB_SIGNAL:
      case B_CCOMP1_SIGNAL:
      case B_CCOMP2_SIGNAL:
         pscale = &B_DET_SCALE;
         break;

      case TEST_PLOT_SIGNAL:
         pscale = &TEST_PLOT_SCALE;
         break;

      case TEST_SIGNAL_SIGNAL:
      default:
         pscale = &COUNTS_SCALE;
         break;
   }
   return pscale;
}



/***********************************************************************/
/* FUNCTION:  SetDetSignalType                                         */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:  To set the signal to a detector type signal               */
/*                                                                     */
/* RETURNED VALUE:  none                                               */
/*                                                                     */
/* GLOBALS USED:  Active Wkfile, Signal1 or 2, Dsp_Out                 */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/***********************************************************************/

static void SetDetSigType( pSIG_TABLE psignal, SIG_TYPE type,
                           CCOMP_MODE ccomp_mode, BIT8 set_wkfile_flag )
{
   DET_TYPE det_type;
   POSITION position;

   INTERRUPTS_OFF
      if ( set_wkfile_flag == TRUE )
      {
         psignal->active_wkfile->signal = (BIT8)type;
      }

      psignal->signal                = type;
      psignal->plot_size             = NOT_PLOT_SIGNAL;
      psignal->ccomp_mode            = ccomp_mode;

      /* Set the scale factor information */
      psignal->pscale = GetDetScaleFactor( type );

      /* Set the type for the signal dsp */
      SetDspSignalType( psignal, type );

      switch ( type )
      {
         case DETA_SIGNAL:
         case DETA_B_SIGNAL:
         case DETB_A_SIGNAL:
         case F_CCOMP1_SIGNAL:
         case F_CCOMP2_SIGNAL:  position = FRONT;
                                det_type = GetDetectorType( position );
                                break;
         case DETB_SIGNAL:
         case B_CCOMP1_SIGNAL:
         case B_CCOMP2_SIGNAL:  position = BACK;
                                det_type = GetDetectorType( position );
                                break;

         default:               det_type = NO_DET;
                                position = FRONT;
      }

      if ( det_type == uECD )
      {
         if ( GetDetDiagLinearMode( position ) )
         {
            psignal->sig_conv_mode = CONV_uECD_TEST;
         }
         else
         {
            psignal->sig_conv_mode = CONV_uECD_LIN;
         }
      }
      else
      {
         if ( det_type == LDID )
         {
            if ( GetDetDiagLinearMode( position ) )
            {
               psignal->sig_conv_mode = CONV_LDID_TEST;
            }
            else
            {
               psignal->sig_conv_mode = CONV_LDID_LIN;
            }
         }
         else
         {
            psignal->sig_conv_mode = NULL_CONV;
         }
      }

   INTERRUPTS_ON
}



/***********************************************************************/
/* FUNCTION:  CheckDetectorPresense                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:  To see if a detector is present and can thus be set to    */
/*           a signal.                                                 */
/*                                                                     */
/* RETURNED VALUE:  UI_ERR return code                                 */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/* CALLS:  GetDetectorType                                             */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/***********************************************************************/

static UI_ERR CheckDetectorPresence( POSITION position )
{
   if ( GetDetectorType( position ) == NO_DET )
   {
      return( NOT_INSTALLED );
   }
   return( OK );
}

#if 0
static UI_ERR CheckSccPresence( pCCOMP_TABLE pccomp )
{
   /* See if there is a valid scc profile stored */
   if ( pccomp->pdata->data_valid_flag == DATA_OK )
   {
      return( OK );
   }

   return( NO_SCC_DATA );

}

static UI_ERR CheckDetAndScc( POSITION position, pCCOMP_TABLE pccomp )
{
   DET_TYPE det_type;
   DET_TYPE ccomp_det_type;

   det_type = GetDetectorType( position );
   ccomp_det_type = GetSccDetectorType( pccomp );

   if ( det_type == NO_DET ) return NOT_INSTALLED;

   /* We allow you to define the signal before you have collected a profile */
   if ( ccomp_det_type == NO_DET ) return OK;

   if ( ccomp_det_type == det_type ) return OK;

   return NOT_COMPATIBLE;
}

#endif


/***********************************************************************/
/* FUNCTION:  CheckFrontBackSignal                                     */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:  To see if both detectors are present and are of the same  */
/*           type.                                                     */
/*                                                                     */
/* RETURNED VALUE:  UI_ERR return code                                 */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/* CALLS:  GetDetectorType                                             */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/***********************************************************************/

static UI_ERR CheckFrontBackSignal( void )
{
   DET_TYPE front, back;

   front = GetDetectorType( FRONT );
   back  = GetDetectorType( BACK );

   if ( front == NO_DET )
   {
      return( NOT_INSTALLED );
   }

   if ( back == NO_DET )
   {
      return( NOT_INSTALLED );
   }

   if ( front == back )
   {
      return( OK );
   }
   else
   {
      return( NOT_COMPATIBLE );
   }

}



/***********************************************************************/
/* FUNCTION:  CheckSignalType                                          */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:  To check that signal type is assigned to an allowable     */
/*           signal.  If the signal source is not installed then it    */
/*           will return the error code NOT_INSTALLED otherwise it     */
/*           will return the error code OK.                            */
/*                                                                     */
/* RETURNED VALUE:  UI_ERR, error code                                 */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/***********************************************************************/

UI_ERR CheckSignalType( SIG_TYPE type )
{
   UI_ERR check_setpt;

   check_setpt = OK;

   if (!((( type >= FIRST_SIGNAL_TYPE ) && ( type <  END_OF_SCALED_SIGNALS )) ||
        (( type >= FIRST_UNSCALED_SIGNAL ) && ( type <  END_OF_SIGNALS ))))
   {
      return INVALID_PARAM;
   }

   switch( type )
   {
      case F_CCOMP1_SIGNAL:
      case F_CCOMP2_SIGNAL:
      case DETA_SIGNAL:
         check_setpt = CheckDetectorPresence( FRONT );
         break;
      case B_CCOMP1_SIGNAL:
      case B_CCOMP2_SIGNAL:
      case DETB_SIGNAL:
         check_setpt = CheckDetectorPresence( BACK );
         break;
      case DETA_B_SIGNAL:
      case DETB_A_SIGNAL:
         check_setpt = CheckFrontBackSignal();
         break;
   }

   return( check_setpt );
}


void SetSccMode( void )
{

   /* See if we should be expanding the test plot */
   if ( ( Signal1.signal == TEST_PLOT_SIGNAL ) ||
        ( Signal2.signal == TEST_PLOT_SIGNAL ) )
   {
      Test_Plot.apply_scc_flag = 1;
   }
   else
   {
      Test_Plot.apply_scc_flag = 0;
   }

   /* See if we should be expanding the test signal */
   if ( ( Signal1.signal == TEST_SIGNAL_SIGNAL ) ||
        ( Signal2.signal == TEST_SIGNAL_SIGNAL ) )
   {
      Test_Signal.apply_scc_flag = 1;
   }
   else
   {
      Test_Signal.apply_scc_flag = 0;
   }

   /* Also update the scc apply control flag */
   if ( ( Signal1.ccomp_mode == ADD_CCOMP1 )
        ||
        (  Signal1.ccomp_mode == SUBTRACT_CCOMP1 )
        ||
        (  Signal2.ccomp_mode == ADD_CCOMP1 )
        ||
        (  Signal2.ccomp_mode == SUBTRACT_CCOMP1 ) )
   {
      Ccomp1.apply_scc_flag = 1;
   }
   else
   {
      Ccomp1.apply_scc_flag = 0;
   }

   if ( ( Signal1.ccomp_mode == ADD_CCOMP2 )
        ||
        (  Signal1.ccomp_mode == SUBTRACT_CCOMP2 )
        ||
        (  Signal2.ccomp_mode == ADD_CCOMP2 )
        ||
        (  Signal2.ccomp_mode == SUBTRACT_CCOMP2 ) )
   {
      Ccomp2.apply_scc_flag = 1;
   }
   else
   {
      Ccomp2.apply_scc_flag = 0;
   }
}



/***********************************************************************/
/* FUNCTION:  SetSignalType                                            */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:  To set the signal type definition.                        */
/*                                                                     */
/* RETURNED VALUE:  UI_ERR return code                                 */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/* CALLS:  SetSignalTypeMain                                           */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/***********************************************************************/

UI_ERR SetSignalType ( pSIG_TABLE psignal, SIG_TYPE type)
{
   return( SetSignalTypeMain ( psignal, type, TRUE ) );
}

UI_ERR SetSignalTypeMain ( pSIG_TABLE psignal, SIG_TYPE type,
                           BIT8 set_wkfile_flag )
{

   UI_ERR  ui_err;

   ui_err = CheckSignalType( type );

   if ( ui_err == OK )
   {
      if ( AlternateSignal( type ) == FALSE )
      {
         switch( type )
         {
         case DETA_SIGNAL:
         case DETB_SIGNAL:
         case DETA_B_SIGNAL:
         case DETB_A_SIGNAL:
             SetDetSigType( psignal, type, DISABLE_CCOMP, set_wkfile_flag );
             break;

         case COL_COMP1_SIGNAL:
             SetDetSigType( psignal, type, ADD_CCOMP1, set_wkfile_flag );
             break;

         case COL_COMP2_SIGNAL:
             SetDetSigType( psignal, type, ADD_CCOMP2, set_wkfile_flag );
             break;

         case F_CCOMP1_SIGNAL:
             SetDetSigType( psignal, type, SUBTRACT_CCOMP1, set_wkfile_flag );
             break;

         case F_CCOMP2_SIGNAL:
             SetDetSigType( psignal, type, SUBTRACT_CCOMP2, set_wkfile_flag );
             break;

         case B_CCOMP1_SIGNAL:
             SetDetSigType( psignal, type, SUBTRACT_CCOMP1, set_wkfile_flag );
             break;

         case B_CCOMP2_SIGNAL:
             SetDetSigType( psignal, type, SUBTRACT_CCOMP2, set_wkfile_flag );
             break;

         case TEST_PLOT_SIGNAL:
             SetDetSigType( psignal, type, EXPAND_TEST_PLOT, set_wkfile_flag);
             break;

         case TEST_SIGNAL_SIGNAL:
             SetDetSigType( psignal, type, EXPAND_TEST_SIGNAL, set_wkfile_flag);
             break;
         };
      }
      else /* We are a plot type signal */
      {
         SetAlternateSignalType( psignal, type, set_wkfile_flag );
      }

      /* This function is called for runtime programmed setpt changes.  We    */
      /* will NOT log runtime setpt changes as a rule.                        */
      if ( set_wkfile_flag == TRUE )
      {
         if ( psignal->chan == SIGNAL1 )
         {
            LogSetptChange( SIGNAL1_TYPE,(INT32)type,0);
         }
         else if ( psignal->chan == SIGNAL2 )
         {
            LogSetptChange( SIGNAL2_TYPE,(INT32)type,0);
         }
      }

   } /* end if ( ui_err == OK ) */

   SetSccMode( );

   return( ui_err );

}

INT32 GetSignalType( pSIG_TABLE psignal )
{
   return ( (INT32)psignal->signal );
}



/***********************************************************************/
/* FUNCTION:  GetSignalScaleMultiplier                                 */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: To return the numerator of the scale factor used to con-   */
/*          vert the signal value to its fundamental units, e.g for    */
/*          temperature, degrees C.                                    */
/*                                                                     */
/* GLOBALS USED:  Signal1, Signal2                                     */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/***********************************************************************/

INT32 GetSignalScaleMultiplier( pSIG_TABLE psignal )
{
   return( psignal->pscale->multiplier );
}

INT32 GetSignalScaleDivisor( pSIG_TABLE psignal )
{
   return( psignal->pscale->divisor );
}


static char const *GetDetSigLabel( POSITION pos, DET_TYPE type )
{
   if (GetCPFDetUnitsLabelPresence( pos ))
   {
      return (const char *)GetCPFDetUnitsLabel( pos );
   }

   switch( type )
   {
      case FID:
         return( &FID_LABEL[0] );
      case TCD:
         return( &TCD_LABEL[0] );
      case ECD:
         return( &ECD_LABEL[0] );
      case uECD:
         return( &uECD_LABEL[0] );
      case NPD:
         return( &NPD_LABEL[0] );
      case FPD:
         return( &FPD_LABEL[0] );
      case AIB:
         return( &AIB_LABEL[0] );
      case LDID:
         return( &LDID_LABEL[0] );
      case NO_DET:
      default:
         return( &UNKNOWN_LABEL[0] );
   }
}

INT32 GetSignalScaleLabel( pSIG_TABLE psignal )
{
   char const *plabel;
   pCCOMP_DATA pcomp;

   plabel = psignal->pscale->plabel;

   switch( (INT32)plabel )
   {
      case 0:  return (INT32)GetDetSigLabel(FRONT, GetDetectorType(FRONT));

      case 1:  return (INT32)GetDetSigLabel(BACK, GetDetectorType(BACK));

      case 2:  pcomp = &Ccomp1_Data;
               return (INT32)GetDetSigLabel(pcomp->det_data_stored,
                                               pcomp->det_type);

      case 3:  pcomp = &Ccomp2_Data;
               return (INT32)GetDetSigLabel(pcomp->det_data_stored,
                                               pcomp->det_type);

      default: return (INT32)plabel;
   }
}



/***********************************************************************/
/* FUNCTION:  DetOnOffChanged                                          */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:  To act on the fact that the on/off state of a detector    */
/*           has changed.                                              */
/*                                                                     */
/* GLOBALS USED:  Dsp_Out                                              */
/*                                                                     */
/* CALLS:  SetDspSignalType                                            */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/***********************************************************************/

void DetOnOffChanged( void )
{
   SetDspSignalType( &Signal1, (SIG_TYPE)Signal1.active_wkfile->signal );
   SetDspSignalType( &Signal2, (SIG_TYPE)Signal2.active_wkfile->signal );
}

/***********************************************************************/
/* FUNCTION:  GetSignalScaleFactor                                     */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:  To return a pointer to the signal scale factor for a      */
/*           given signal type.                                        */
/*                                                                     */
/* RETURNED VALUE: pSCALE_CONSTANTS                                    */
/*                                                                     */
/* GLOBALS USED: none                                                  */
/*                                                                     */
/* CALLS: GetAlternateSignalScale, GetDetectorScale, AlternateSignal   */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/***********************************************************************/

SCALE_CONSTANTS const *GetSignalScaleFactor( SIG_TYPE type )
{
   if ( AlternateSignal( type ) )
   {
      if ( UnscaledSignal( type ) )
      {
         return &COUNTS_SCALE;
      }
      else
      {
         return GetAlternateSignalScale( GetAlternateSignalIndex( type ) );
      }
   }
   else
   {
         return GetDetScaleFactor( type );
   }
}

INT32 GetPresSignalValue( SIG_TYPE type )
{
   PLOT_CONSTANTS values;
   INT16 index;
   INT32 signal;

   index = GetAlternateSignalIndex( type );

   SetPlotConstants( type, &values );

   signal = GetSignalFromSizeAndAddr( ALT_SIG_TYPE_TABLE[index].size,
                                      ALT_SIG_TYPE_TABLE[index].addr );

   signal -= values.offset;

   return SignedQuadWordMultiplyDivide( signal, values.multiplier,
                                        values.divisor );
}

INT32 GetAlternateSignalValue( SIG_TYPE type )
{
   PLOT_CONSTANTS const *values;
   INT16 index;
   INT32 signal;

   /* Check for pneumatics signal with varying scale factors */
   if ( CalculatedConstants( type ) )
   {
      return GetPresSignalValue( type );
   }

   index = GetAlternateSignalIndex( type );

   values = ALT_SIG_TYPE_TABLE[index].pconstants;

   signal = GetSignalFromSizeAndAddr( ALT_SIG_TYPE_TABLE[index].size,
                                      ALT_SIG_TYPE_TABLE[index].addr );

   signal -= values->offset;

   return SignedQuadWordMultiplyDivide( signal, values->multiplier,
                                        values->divisor );
}


/***********************************************************************/
/* FUNCTION:  SetSignalTypeForDiagnostics                              */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:  To set the signal type to for diagnostics.  This will set */
/*           the instrument in diagnostics mode, indicating that the   */
/*           signal has been changed from that stored in the workfile. */
/*                                                                     */
/* RETURNED VALUE:  UI_ERR return code                                 */
/*                                                                     */
/* GLOBALS USED:  Signal1, Signal2                                     */
/*                                                                     */
/* CALLS:  SetSignalTypeMain                                           */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/***********************************************************************/

UI_ERR SetSignalTypeForDiagnostics( pSIG_TABLE psignal, SIG_TYPE type )
{
   UI_ERR return_code;

   /* Don't set diagnostics mode bit if we aren't changing the signal */
   if ( type == (SIG_TYPE)GetSignalType( psignal ) ) return OK;

   return_code = SetDiagMode( ON );

   if ( return_code != OK )
   {
      return( return_code );
   }

   return SetSignalTypeMain ( psignal, type, FALSE );
}
